using System.Collections.Generic;
using UnityEngine;

namespace M13.Phys
{
    public static class DispersedBoundsManager
    {
        public static HashSet<AABB> DispersedBounds = new();
        public static void Register(AABB aabb)
        {
            if (!DispersedBounds.Contains(aabb))
                DispersedBounds.Add(aabb);
        }

        public static void Register(GameObject obj)
        {
            Bounds bounds = obj.GetComponent<MeshFilter>().mesh.bounds;
            AABB aabb = new(bounds.center + obj.transform.position, bounds.size, AABBType.Block);
            if (!DispersedBounds.Contains(aabb))
                DispersedBounds.Add(aabb);
            Debug.Log($"center:{bounds.center + obj.transform.position}, size:{bounds.size}");
        }
        
        
        /// <summary>
        /// 获取可能发生碰撞的其他AABB
        /// </summary>
        /// <param name="aabb"></param>
        /// <returns></returns>
        public static HashSet<AABB> RetrieveCollisionCandidates(AABB aabb)
        {
            return DispersedBounds;
        }
    }
}